package com.itheima.edu.day19File.day20ObjectStream;


import java.io.*;

public class StudentAdmin {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        Student stu1 = new Student("zhangsan",23);
        Student stu2 = new Student("lisi",24);
        Student stu3 = new Student("wangwu",25);
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("D:\\Develop\\javaCode\\itheima-edu-info-manager\\src\\com\\itheima\\edu\\day19File\\day20ObjectStream\\b.txt"));
        oos.writeObject(stu1);
        oos.writeObject(stu2);
        oos.writeObject(stu3);
        oos.close();

        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("D:\\Develop\\javaCode\\itheima-edu-info-manager\\src\\com\\itheima\\edu\\day19File\\day20ObjectStream\\b.txt"));

        /*
        Student stu01 = (Student)ois.readObject();
        Student stu02 = (Student)ois.readObject();
        Student stu03 = (Student)ois.readObject();
        //问题：为什么同样的方法会打印不同的结果？

        System.out.println(stu01);
        System.out.println(stu02);
        System.out.println(stu03);
        System.out.println(stu03);
        System.out.println(stu02);
        */

        //用while死循环输出
               while(true){
            try {
                Object o = ois.readObject();
                System.out.println(o);
                //问题：为什么同样的方法会打印不同的结果？
            } catch (EOFException e) {
                break;
            }
        }



        ois.close();
    }
}
